<template>
  <div>
    <h2>管理员添加</h2>
    <table class="table table-bordered">
      <tbody>
      <tr>
        <td align="right">账号</td>
        <td>
          <input type="text" v-model="info.UserName">
        </td>
      </tr>
      <tr>
        <td align="right">密码</td>
        <td>
          <input type="password" v-model="info.UserPed">
        </td>
      </tr>
      <tr>
        <td align="right"></td>
        <td>
          <input type="button" value="登陆" class="btn btn-primary" @click="add">
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import {useRouter} from 'vue-router'
import axios from "axios";
const router = useRouter()

let info:any = reactive({
  UserName:'',
  UserPed:''
})

const add = () => {
  if(info.UserName === ''){
    alert('账号不能为空');
    return;
  }
  if(info.UserPed === ''){
    alert('密码不能为空');
    return;
  }

  axios({
    url:'/api/Admins/AddAdmin',
    method:'post',
    data:info
  })
      .then((res) => {
        console.log(res)
        if(res.data==-1){
          alert('账号重复 请重新注册');
          return;
        }
        if(res.data>0){
          alert('管理员添加成功');
          return;
        }
        else{
          alert('管理员添加失败');
          return;
        }
      })
      .catch((err)=>{
        console.log(err)
      })
}
</script>

<style scoped>

</style>